package com.yuzhyn.hiops.app.application.controller.web;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

/**
 * @author inc
 */
@Slf4j
@RequestMapping({"web/common", "web/com"})
@Controller
public class CommonController {
    /**
     * 通用Web请求入口
     *
     * @param path
     * @param page
     * @return
     */
    @GetMapping("/{path}/{page}")
    String def(@PathVariable String path, @PathVariable String page) {
        return path + "/" + page;
    }

    /**
     * 通用Web请求入口（带参数）
     *
     * @param path
     * @param page
     * @param model
     * @param data
     * @return
     */
    @GetMapping("/m/{path}/{page}")
    String def_mod(@PathVariable String path, @PathVariable String page, Model model, @RequestParam(required = false) Map<String, String> data) {
        if (data != null && data.size() > 0) {
            for (Map.Entry<String, String> entry : data.entrySet()) {
                model.addAttribute(entry.getKey(), entry.getValue());
            }
        }
        return path + "/" + page;
    }

    /**
     * 通用Web请求入口
     *
     * @param path1
     * @param path2
     * @param page
     * @return
     */
    @GetMapping("/{path1}/{path2}/{page}")
    String def3(@PathVariable String path1, @PathVariable String path2, @PathVariable String page) {
        return path1 + "/" + path2 + "/" + page;
    }

    /**
     * 通用Web请求入口（带参数）
     *
     * @param path1
     * @param path2
     * @param page
     * @param model
     * @param data
     * @return
     */
    @GetMapping("/m/{path1}/{path2}/{page}")
    String def3_mod(@PathVariable String path1, @PathVariable String path2, @PathVariable String page, Model model, @RequestParam(required = false) Map<String, String> data) {
        if (data != null && data.size() > 0) {
            for (Map.Entry<String, String> entry : data.entrySet()) {
                model.addAttribute(entry.getKey(), entry.getValue());
            }
        }
        return path1 + "/" + path2 + "/" + page;
    }
}
